package com.study.lihan.springmvc.service;

import com.study.lihan.springmvc.bean.MyException;
import com.study.lihan.springmvc.mapper.MainThreadMapper;
import com.study.lihan.springmvc.mapper.ZiThreadMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TxService {

    @Autowired
    public MainThreadMapper mainThreadMapper;
    @Autowired
    public ZiThreadMapper ziThreadMapper;

    @Autowired
    @Lazy
    private TxService txService;
    //@Transactional(rollbackFor = Exception.class)
    public void threadTestTransactional() {
        mainThreadMapper.updateById(1,"main");
      //  txService.hello();
    }
    @Transactional(rollbackFor = Exception.class)
    public void hello(){
        ziThreadMapper.updateById(1,"zi");
        throw new MyException("抛出异常");
    }
}
